package com.easy.service.Impl;

import com.easy.bean.Orders;
import com.easy.mapper.OrdersMapper;
import com.easy.service.OrdersService;
import com.easy.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
@Transactional(readOnly = true) // 默认只读
public class OrdersServiceImpl implements OrdersService {

    @Autowired
    OrdersMapper ordersMapper;
    @Override
    @Transactional(rollbackFor = Exception.class) // 写操作
    public Orders add(Orders orders) {
        ordersMapper.add(orders);
        Orders result = ordersMapper.one(orders.getOrder_id());
        return result;
    }

    @Override
    @Transactional(rollbackFor = Exception.class) // 写操作
    public int del(Integer id) {
        return ordersMapper.del(id);
    }

    @Override
    @Transactional(rollbackFor = Exception.class) // 写操作
    public Orders edit(Orders orders) {
        ordersMapper.edit(orders);
        Orders result = ordersMapper.one(orders.getOrder_id());
        return result;
    }

    @Override
    @Transactional(rollbackFor = Exception.class) // 写操作
    public List<Orders> all(Orders orders) {
        return ordersMapper.all(orders);
    }

    @Override
    @Transactional(rollbackFor = Exception.class) // 写操作
    public Orders one(Integer id) {
        return ordersMapper.one(id);
    }

    @Override
    @Transactional(rollbackFor = Exception.class) // 写操作
    public void page(Page page, Orders order) {
        int count=ordersMapper.pageCount(order);
        Object data=ordersMapper.page(page,order);
        page.setCount(count);
        page.setData(data);
    }
}
